<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/25 0025
 * Time: 上午 10:04
 */

namespace app\home\controller;


use think\Db;

class Moneycontrol extends HomeBase
{
    //资金监管列表
    public function getlist(){
        $current=input('current');
        if(!$current){
            $current=1;
        }
        $pagenums=input('pagenums');
        if(!$pagenums){
            $pagenums=50;
        }
        $nowpagenums=($current-1)*$pagenums;
        $order=input('order');
        if(!$order){
            $order='id DESC';
        }

        $total=Db::name('Zijincat')->count('id');
        $info=Db::name('Zijincat')
            ->order($order)
            ->limit($nowpagenums,$pagenums)
            ->select();

        if($info){
            foreach ($info as $key=>$value){
                $info[$key]['danwei']=$this->get_danwei($value['bid']);
                $info[$key]['times']=time_nianyueri($value['create_time']);
                $info[$key]['zijinprice']=Db::name('Zijininfo')->where('catid',$value['id'])->sum('price');
                $data=Db::name('Zijininfo')->where('catid',$value['id'])->find();
                $info[$key]['zmid']=$data['zmid'];
            }

            $datas['status']=1;
            $datas['info']=$info;
            $datas['total']=$total;
            $datas['current']=$current;
        }else{
            $datas['status']=0;
            $datas['info']='无数据！';
            $datas['total']=$total;
            $datas['current']=$current;
        }

        return json($datas);
    }
    function  get_danwei($id){
        if($id){
            $danwei=Db::name('Danwei')->where('id',$id)->value('bname');
            return $danwei;
        }
    }
    //查看详情
    public function getdetail(){
        $id=input('id');
        if($id){
            $info=Db('Zijincat')->where('id',$id)->find();
            if($info){
                $info['danwei']=$this->get_danwei($info['bid']);
                $info['create_time']=time_nianyueri($info['create_time']);
                $datas['status']=1;
                $datas['info']=$info;
            }else{
                $datas['status']=0;
                $datas['info']='无数据！';
            }
        }else{
            $datas['status']=0;
            $datas['info']='无参数！';
        }

        return json($datas);
    }
}